from typing import Optional
from sqlmodel import SQLModel
from fastapi_amis_admin import amis
from fastapi_amis_admin.models import Field
from ..common import AppBaseModel

class SysRole(AppBaseModel, title=True):
    __tablename__ = 'sys_role'
    __table_args__ = {'extend_existing': True}
    name: Optional[str] = Field(title='角色名称')
    app_code: Optional[str] = Field(index=True, title='所属系统编码')
    remark: Optional[str] = Field(title='备注')
    dept_id: Optional[int] = Field(index=True, title='部门ID',
                                       serialization_alias="deptId", validation_alias="deptId", alias="deptId")
    data_permission_type: Optional[str] = Field(title='数据权限类型, 数据字典(data_permission_type)',
                                       serialization_alias="dataPermissionType", validation_alias="dataPermissionType", alias="dataPermissionType")


class SysRoleDataScope(SQLModel, title=True):
    __tablename__ = 'sys_role_data_scope'
    __table_args__ = {'extend_existing': True}
    id: Optional[int] = Field(primary_key=True, title='id')
    role_id: Optional[int] = Field(index=True, title='角色ID')
    dept_id: Optional[int] = Field(title='部门ID')


class SysRoleMenu(SQLModel, title=True):
    __tablename__ = 'sys_role_menu'
    __table_args__ = {'extend_existing': True}
    id: Optional[int] = Field(primary_key=True, title='id')
    role_id: Optional[int] = Field(index=True, title='角色ID')
    menu_id: Optional[int] = Field(index=True, title='菜单ID')
    app_code: Optional[str] = Field(index=True, title='所属系统编码')


class SysRoleUser(SQLModel, title=True):
    __tablename__ = 'sys_role_user'
    __table_args__ = {'extend_existing': True}
    id: Optional[int] = Field(primary_key=True, title='id')
    role_id: Optional[int] = Field(index=True, title='角色ID')
    user_id: Optional[int] = Field(index=True, title='用户ID')
    app_code: Optional[str] = Field(index=True, title='所属系统编码')


class SysUserDept(SQLModel, title=True):
    __tablename__ = 'sys_user_dept'
    __table_args__ = {'extend_existing': True}
    id: Optional[int] = Field(primary_key=True, title='id')
    user_id: Optional[int] = Field(nullable=False, title='用户id')
    dept_id: Optional[int] = Field(nullable=False, title='部门id')

# Create your models here.

# class Category(SQLModel, table=True):
#     __tablename__ = 'blog_category'
#     id: Optional[int] = Field(default=None, primary_key=True, nullable=False)
#     name: str = Field(
#         title='Category Name',
#         unique=True,
#         index=True,
#         nullable=False,
#     )
#     description: str = Field(default='', title='Description', amis_form_item=amis.Textarea())
#     is_active: bool = Field(False, title='Is Active')
